﻿//====================================================================
// Create by Daniel
// file： YCModuleArtical.cs
// project ：Myproject
// Build time：2012-09-09
// modify:
// description:
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Linq;
using YunCMS.Model;
using YunCMS.IDAL;

namespace YunCMS.DAL
{
    /// <summary>
    /// Data Access Layer of dbo.YC_Module_Artical.
    /// </summary>
    public partial class YCModuleArticalDAL : ModuleDAL<YCModuleArtical>, IYCModuleArticalDAL
    {
        #region constructor

        /// <summary>
        /// constractor
        /// </summary>
        public YCModuleArticalDAL()
        {
        }

        #endregion

        #region QueryString

        protected override string AddQueryStr
        {
            get
            {
                StringBuilder sqlStr = new StringBuilder();
                sqlStr.Append("insert into YC_Module_Artical(");
                sqlStr.Append("Title,Keywords,Summary,Content,Author,Description,CategoryID,IsHomePage,AddTime,UpdateTime,Access,Hits,Editor,IsPopular,ImageUrl,LinkUrl,Source,DiggTop,DiggStep,Active,Lang)");
                sqlStr.Append(" values (");
                sqlStr.Append("@Title,@Keywords,@Summary,@Content,@Author,@Description,@CategoryID,@IsHomePage,getdate(),getdate(),@Access,@Hits,@Editor,@IsPopular,@ImageUrl,@LinkUrl,@Source,@DiggTop,@DiggStep,@Active,@Lang)");
                sqlStr.Append(";select @@IDENTITY");

                return sqlStr.ToString();
            }
        }

        protected override string UpdateQueryStr
        {
            get
            {
                StringBuilder sqlStr = new StringBuilder();
                sqlStr.Append("update YC_Module_Artical set ");
                sqlStr.Append("Title=@Title,Keywords=@Keywords,Summary=@Summary,Content=@Content,Author=@Author,Description=@Description,CategoryID=@CategoryID,IsHomePage=@IsHomePage,UpdateTime=getdate(),Access=@Access,Hits=@Hits,Editor=@Editor,IsPopular=@IsPopular,ImageUrl=@ImageUrl,LinkUrl=@LinkUrl,Source=@Source,DiggTop=@DiggTop,DiggStep=@DiggStep,Active=@Active,Lang=@Lang");
                sqlStr.Append(" where ID=@ID");

                return sqlStr.ToString();
            }
        }
        #endregion

        #region -----------Methods-----------  

        protected override string TableName
        {
            get { return "YC_Module_Artical"; } 
        }

        /// <summary>
        ///Get YCModuleArtical Entity
        /// </summary>
        /// <param name="dr">dr</param>
        /// <returns>YCModuleArtical Entity</returns>
        public override YCModuleArtical PopulateModelFromDr(IDataReader dr)
        {
            YCModuleArtical Obj = base.PopulateModelFromDr(dr);

            Obj.Summary = dr["Summary"].ToString();
            Obj.Editor = dr["Editor"].ToString();
            Obj.ImageUrl = dr["ImageUrl"].ToString();
            Obj.LinkUrl = dr["LinkUrl"].ToString();

            return Obj;
        }

        protected override List<SqlParameter> GetSelfParams(YCModuleArtical model)
        {
            List<SqlParameter> extParams = new List<SqlParameter>(){
                            new SqlParameter("@Summary",SqlDbType.NVarChar),                            
                            new SqlParameter("@Editor",SqlDbType.NVarChar),
                            new SqlParameter("@ImageUrl",SqlDbType.NVarChar),
                            new SqlParameter("@LinkUrl",SqlDbType.NVarChar)
                            
            };

            if (model.Summary != String.Empty)
                extParams[0].Value = model.Summary;
            else
                extParams[0].Value = DBNull.Value;
            if (model.Editor != String.Empty)
                extParams[1].Value = model.Editor;
            else
                extParams[1].Value = DBNull.Value;

            if (model.ImageUrl != String.Empty)
                extParams[2].Value = model.ImageUrl;
            else
                extParams[2].Value = DBNull.Value;
            if (model.LinkUrl != String.Empty)
                extParams[3].Value = model.LinkUrl;
            else
                extParams[3].Value = DBNull.Value;

            return extParams;
        }
       
        #endregion
    }
}



